import {
  _decorator,
  Color,
  Component,
  Sprite,
  SpriteFrame,
  UITransform,
} from "cc";
import { STEADY_VALUE } from "../../Test1/Kits/SteadyValues";
import { Kit } from "../../Test1/Kits/Kit";
const { ccclass, property } = _decorator;

@ccclass("Pretreatment")
export class Pretreatment extends Component {
  @property
  assetMap2: Map<string, Promise<SpriteFrame[]>> = new Map();

  async getSpriteFrames(path: string) {
    const kit = Kit.getInstance();
    let spriteFrames = await kit.loadImages(path);
    let res = Promise.all(spriteFrames);
    return res;
  }

  handleAssetsMap2(path: string) {
    let value = this.getSpriteFrames(path);
    this.assetMap2.set(path, value);
  }

  async pretreatmentSetting(defaultImgPath: string) {
    const spriteComponent = this.node.getComponent(Sprite);
    const transform = this.node.getComponent(UITransform);

    const newColor = new Color(255, 255, 255);
    spriteComponent.color = newColor;

    // 设置宽高
    transform.setContentSize(
      STEADY_VALUE.FIRST.WIDTH,
      STEADY_VALUE.FIRST.HEIGHT
    );

    let coverPictures = await this.assetMap2.get(defaultImgPath);
    spriteComponent.spriteFrame = coverPictures[0];
  }
}
